/*
 * @Author: zi.yang
 * @Date: 2022-02-07 23:20:49
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-02-08 00:06:07
 * @Description: In User Settings Edit
 * @FilePath: \api-generator\app\service\file.js
 */
'use strict';
const Service = require('egg').Service;
const AjaxResponse = require('../utils/AjaxResponse');

class FileService extends Service {
  async add(fileInfo) {
    const { ctx } = this;
    try {
      await ctx.model.File.create(fileInfo);
      const data = await ctx.model.File.findOne({ filename: fileInfo.filename });
      return AjaxResponse.success({ data });
    } catch (error) {
      return AjaxResponse.error({ error });
    }
  }
  async getFileById({ fileId }) {
    const { ctx } = this;
    try {
      const data = await ctx.model.File.findById(fileId);
      return AjaxResponse.success({ data });
    } catch (error) {
      return AjaxResponse.error({ error });
    }
  }
}

module.exports = FileService;
